import { USER_LOGIN, USER_LOGOUT } from '../actionTypes';

function initialState() {
  const userInfo = window.localStorage.getItem('userInfo');
  if (userInfo) {
    return JSON.parse(userInfo);
  }
  return null;
}
const user = (state = initialState(), action) => {
  switch (action.type) {
    case USER_LOGIN:
      return {
        ...state,
        ...action.payload,
      };
    case USER_LOGOUT:
      return null;
    default:
      return state;
  }
};

export default user;
